package cn.caplike.demo.spring.bean.lifecycle;

import cn.caplike.demo.spring.bean.lifecycle.service.impl.AccountServiceImpl;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class LifeCycleTest {

    public static void main(String[] args) {
        // 1.获取核心容器对象
        final ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext("bean.xml");

        // 2.根据id获取Bean对象
        final AccountServiceImpl accountServiceImpl = (AccountServiceImpl) applicationContext.getBean("accountServiceImpl");
        accountServiceImpl.setName("caplike");
        accountServiceImpl.saveAccount();

        // 手动关闭容器, 触发 destroy-method
        applicationContext.close();
    }
}
